<html>
<head>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/wangEditor/3.1.1/wangEditor.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/wangEditor/10.0.13/wangEditor.min.js"></script>
    <script src="${ctx}/layui/lay/modules/laydate.js"></script>
    <script src="${ctx}/js/iw.js"></script>
    <style>
        [class*='col-xs-'] {
            margin-bottom: 10px;
        }

        .hide {
            display: none;
        }

        .pr_no {
            padding-right: 0;
        }
    </style>

</head>
<body class="container-fuild" style="padding-top: 8px;">
<form class="form-horizontal" id="form">
    <div class="col-xs-6">
        <div class="form-group">
            <label for="title" class="col-sm-4 control-label">应用名称</label>
            <div class="col-sm-8">
                <input type="text" style="display:none;" id="taskId" name="taskId"
                       value="<#if task??>${task.taskId!''}</#if>"/>
                <input type="text" class="form-control" id="title" name="title" onChange="change()" placeholder="填入应用名称"
                       value="<#if task??>${task.title}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">任务总量（单位:个）</label>
            <div class="col-sm-8">
                <input type="number" class="form-control" id="total" name="total" placeholder="填入任务总量，填0表示不设总量"
                       value="<#if task??>${task.total}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="packagename" class="col-sm-4 control-label">应用包名</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="packagename" name="packagename" placeholder="填入应用包名"
                       value="<#if task??>${task.packagename}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">应用大小(填写单位)</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="size" name="size" placeholder="填入应用包大小，需含单位"
                       value="<#if task??>${task.size}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label">应用市场</label>
            <div class="col-sm-8">
                <select class="form-control" id="appStore" name="appStore" onChange="change()">
                    <option value="">请选择应用市场</option>
                    <#list appStores as appStore>
                        <option value="${appStore.code}"
                                <#if task?? && task.appStore == appStore.code>selected</#if>><#if appStore.name??>${appStore.name}<#else>${appStore.code}</#if></option>
                    </#list>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">&nbsp;&nbsp;关键词&nbsp;&nbsp;</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="keywords" name="keywords" onChange="change()"
                       placeholder="填入应用关键词" value="<#if task??>${task.keywords}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-4 control-label">应用图标</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="icon" name="icon" placeholder="填入图标链接地址"
                       value="<#if task??>${task.icon}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">试玩时间(单位:分钟)</label>
            <div class="col-sm-8">
                <input type="number" class="form-control" id="minutes" name="minutes" onChange="change()"
                       placeholder="填入应用试玩时间，单位：分钟" value="<#if task??>${task.minutes}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label">市场排名</label>
            <div class="col-sm-8">
                <input type="number" class="form-control" id="rank" name="rank" onChange="change()"
                       placeholder="填入应用在市场排名" value="<#if task??>${task.rank}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">每日限量(单位:个)</label>
            <div class="col-sm-8">
                <input type="number" class="form-control" id="amount" name="amount" placeholder="填入每日限量，填0表示不限量"
                       value="<#if task??>${task.amount}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label">客户名称</label>
            <div class="col-sm-8">
                <select id="customer" name="customer" style="height: 34px;width: 253px;border-radius: 4px;">
                    <option value="zy">自营</option>
                    <#if customlist?? && ((customlist?size)>0)>
                        <#list customlist as list>
                            <#if task??>
                                <option value="${list.customId}"
                                        <#if list.customId == task.customer>selected</#if> >${list.name}</option>
                            <#else >
                                <option value="${list.customId}">${list.name}</option>
                            </#if>

                        </#list>
                    </#if>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">客户单价(单位:分)</label>
            <div class="col-sm-8">
                <input type="number" class="form-control" id="increase" name="increase"
                       placeholder="当价格等于0时不可选择“按比例”奖励模式" value="<#if task??>${task.increase}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label">是否审核</label>
            <div class="col-sm-8">
                <select class="form-control" id="needCheck" name="needCheck">
                    <#list booleans as b>
                        <option value="${b}" <#if task?? && task.needCheck == b>selected</#if>>${b.title}</option>
                    </#list>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">指定设备</label>
            <div class="col-sm-8">
                <select class="form-control" id="channel" name="channel">
                    <option value="" <#if task?? && task.channel == ''>selected</#if>>不限设备</option>
                    <option value="vivo" <#if task?? && task.channel == 'vivo'>selected</#if>>限vivo</option>
                    <option value="oppo" <#if task?? && task.channel == 'oppo'>selected</#if>>限oppo</option>
                    <option value="huawei" <#if task?? && task.channel == 'huawei'>selected</#if>>限huawei</option>
                    <option value="meizu" <#if task?? && task.channel == 'meizu'>selected</#if>>限meizu</option>
                    <option value="test" <#if task?? && task.channel == 'test'>selected</#if>>限测试版本</option>
                    <option value="xiaomi" <#if task?? && task.channel == 'xiaomi'>selected</#if>>限小米</option>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label">任务排序</label>
            <div class="col-sm-8">
                <input type="number" class="form-control" id="sort" name="sort" placeholder="升序排序"
                       value="<#if task??>${task.sort}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">计算奖励(单位:分)</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="worth" name="worth" placeholder="随机奖励格式n:m，其他填n，单位：分"
                       value="<#if task??>${task.worth}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label">奖励类型</label>
            <div class="col-sm-8">
                <select class="form-control" id="type" name="type">
                    <#list types as type>
                        <option value="${type}" <#if task?? && task.type == type>selected</#if>>${type.title}</option>
                    </#list>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">任务状态</label>
            <div class="col-sm-8">
                <select class="form-control" id="status" name="status">
                    <option value="On" <#if task?? && task.status == 'On'>selected</#if>>上架</option>
                    <option value="Off" <#if task?? && task.status == 'Off'>selected</#if>>下架</option>
                    <option value="Wait" <#if task?? && task.status == 'Wait'>selected</#if>>待上架</option>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label">奖励模式</label>
            <div class="col-sm-8">
                <select class="form-control" id="reward" name="reward">
                    <#list rewards as reward>
                        <option value="${reward}"
                                <#if task?? && task.reward == reward>selected</#if>>${reward.title}</option>
                    </#list>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">视频指南</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="media" name="media" placehotask="填入soso引导指南链接地址"
                       value="<#if task??>${task.media}<#else>http://p5vcsyy4d.bkt.clouddn.com/video_soso_task.mp4</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6" style="clear: left;">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label">是否首面显示</label>
            <div class="col-sm-8">

                <input name="showinhp" id="showinhp" type="checkbox" <#if task?? && task.showinhp == 1>checked</#if>
                       data-size="mini" value="1"/>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">任务预计用时(分)</label>
            <div class="col-sm-8">
                <input type="number" class="form-control" id="taskTime" name="taskTime" placeholder="预估任务用时单位（分钟）"
                       value="<#if task??>${task.taskTime!''}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label">展示奖励</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="label" name="label" placeholder="填入展示奖励，如：奖励0.9元"
                       value="<#if task??>${task.label}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no">任务要求</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="mission" name="mission" placeholder="任务要求"
                       value="<#if task??>${task.mission!''}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label pr_no" style="padding-left: 0">承诺审核时间(分)</label>
            <div class="col-sm-8">
                <input type="number" class="form-control" id="auditTime" name="auditTime" placeholder="承诺审核时间单位（分钟）"
                       value="<#if task??>${task.auditTime!''}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-4 control-label pr_no">任务自动上架时间</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="autoTime" name="autoTime" autocomplete="off" placeholder="不填写标识没有开启" value="<#if task??>${task.autoTime!''}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-4 control-label pr_no">任务自动下架时间</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="autoOffTime" autocomplete="off" name="autoOffTime" placeholder="不填写标识没有开启" value="<#if task??>${task.autoOffTime!''}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-4 control-label pr_no">用户最小金额限制(分)</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="minMoney" name="minMoney" placeholder="0为没有金额限制" value="<#if task??>${task.minMoney!''}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-4 control-label">是否可重做</label>
            <div class="col-sm-8">
                <#--  <#if
                  是  <input name="redo" type="radio" &lt;#&ndash;<#if task?? && task.redo == 1>checked</#if>&ndash;&gt; data-size="mini" value="1"/>
                  否  <input name="redo" type="radio" &lt;#&ndash;<#if task?? && task.redo == 1>checked</#if>&ndash;&gt; data-size="mini" value="0"/>-->
                <#if task??>
                    <#if task.redo == 0>
                        是  <input type="radio" name="redo" value=1 title="是">
                        否  <input type="radio" name="redo" value=0 title="否" checked>
                    <#else>
                        是  <input type="radio" name="redo" value=1 title="是" checked>
                        否  <input type="radio" name="redo" value=0 title="否">
                    </#if>
                <#else >
                    是  <input type="radio" name="redo" value=1 title="是">
                    否 <input type="radio" name="redo" value=0 title="否" checked>
                </#if>
            </div>
        </div>
    </div>


    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label">可获得奖励倍数</label>
            <div class="col-sm-7">
                <select class="form-control" id="awardMultiple" name="awardMultiple">
                    <option value="1" <#if taskScreenshot?? && taskScreenshot.awardMultiple == 1>selected</#if>>1</option>
                    <option value="2" <#if taskScreenshot?? && taskScreenshot.awardMultiple == 2>selected</#if>>2</option>
                    <option value="3" <#if taskScreenshot?? && taskScreenshot.awardMultiple == 3>selected</#if>>3</option>
                    <option value="4" <#if taskScreenshot?? && taskScreenshot.awardMultiple == 4>selected</#if>>4</option>
                    <option value="5" <#if taskScreenshot?? && taskScreenshot.awardMultiple == 5>selected</#if>>5</option>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label">失败可重做次数</label>
            <div class="col-sm-7">
                <select class="form-control" id="failTimes" name="failTimes">
                    <option value="0" <#if taskScreenshot?? && taskScreenshot.failTimes == 0>selected</#if>>0</option>
                    <option value="1" <#if taskScreenshot?? && taskScreenshot.failTimes == 1>selected</#if>>1</option>
                    <option value="2" <#if taskScreenshot?? && taskScreenshot.failTimes == 2>selected</#if>>2</option>
                    <option value="3" <#if taskScreenshot?? && taskScreenshot.failTimes == 3>selected</#if>>3</option>
                    <option value="4" <#if taskScreenshot?? && taskScreenshot.failTimes == 4>selected</#if>>4</option>
                    <option value="5" <#if taskScreenshot?? && taskScreenshot.failTimes == 5>selected</#if>>5</option>
                    <option value="9999" <#if taskScreenshot?? && taskScreenshot.failTimes == 9999>selected</#if>>不限</option>
                </select>
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label">任务分类</label>
            <div class="col-sm-7">
                <select class="form-control" id="taskCategoryId" name="taskCategoryId">
                    <#list taskClassifys as taskClassify>
                        <option value="${taskClassify.id}" <#if taskScreenshot?? && taskScreenshot.taskCategoryId??&&taskScreenshot.taskCategoryId == taskClassify.id>selected</#if>>${taskClassify.categoryName}</option>
                    </#list>
                </select>
            </div>
        </div>
    </div>

    <div class="col-xs-6">
        <div class="form-group">
            <label for="size" class="col-sm-5 control-label pr_no">任务标签</label>
            <div class="col-sm-1" style="padding-top: 4px;width:200px;">
                <#list taskTags as taskTag>

                    <input name="taskTagIds" type="checkbox" <#if tags?? && tags?seq_contains("${taskTag.id}")>checked</#if> data-size="mini"
                           value="${taskTag.id}"/>${taskTag.tagName}

                </#list>
            </div>

        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-5 control-label pr_no">任务简介</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="taskIntroduce" name="taskIntroduce" placeholder="请输入任务简介"
                       value="<#if taskScreenshot??>${taskScreenshot.taskIntroduce}</#if>">
            </div>
        </div>
    </div>
    <div class="col-xs-6">
        <div class="form-group">
            <label for="icon" class="col-sm-5 control-label pr_no">任务备注</label>
            <div class="col-sm-7">
                <input type="text" class="form-control" id="taskRemarks" name="taskRemarks" placeholder="请输入任务备注"
                       value="<#if taskScreenshot??>${taskScreenshot.taskRemarks}</#if>">
            </div>
        </div>
    </div>

    <div class="col-xs-12" style="padding-left: 63px">
        <div class="form-group">
            <label for="size" class="control-label">文本描述:</label>
            <#--<div class="col-sm-8"></div>-->
        </div>
    </div>

    <#--<div class="col-xs-11 col-xs-offset-1">
        <input type="text" style="display:none" id="contents" name="contents"/>
        <div class="col-sm-12" id="content">
        </div>
    </div>

    <div class="col-xs-11 col-xs-offset-1">
        <input type="text" style="display:none" id="images" name="images"/>
        <div id="imgs"></div>
    </div>-->

    <div class="col-xs-12" style="padding-left: 60px">
        <button type="button" id="add_btn" class="add_btn">添加步骤（图文）</button>
        <button type="button" id="add_btn2" class="add_btn">添加步骤（输入框：输入）</button>

        <button type="button" id="add_btn4" class="add_btn">添加步骤（图文:非上传图片）</button>
        <input type="hidden" id="contents" name="contents"/>
    </div>

    <div class="col-xs-12" style="padding: 0 40px 0 60px" id="_contents">

    </div>
</form>
<div class="col-xs-2" style="text-align: center;width: 100%">
    <button style="width: 85px;" class="btn btn-success" id="save_btn">保存</button>
</div>
<script>

    //时间选择器
    $(document).ready(function () {
        laydate.render({
            elem: '#autoTime'
            ,type: 'time'
        });
        laydate.render({
            elem: '#autoOffTime'
            ,type: 'time'
        });
    });

    var es = [];


    var addImage = function (content) {
        var index = Math.round(Math.random() * 10000);
        var container = $("<div>").attr("id", "step" + index);
        var div = $("<div>").attr("id", "editor" + index)
        var imgs = $("<div>").attr("id", "img" + index);
        var del = $("<button>").attr("type", "button").attr("id", "del" + index).text("删除").css({
            "float": "right",
            "margin": "10px 15px"
        }).click(function () {
            if (confirm("是否删除该步骤？")) {
                $("#step" + index).remove();
                for (var i = 0; i < es.length; i++) {
                    if (es[i].index == index) {
                        es.splice(i, 1);
                    }
                }
            }
        });
        var clearfix = $("<div>").css({
            "clear": "both"
        });
        container.append(div).append(imgs).append(del).append(clearfix);
        $("#_contents").append(container);
        var E = window.wangEditor;
        var editor = new E('#editor' + index);
        editor.customConfig.uploadImgShowBase64 = true;
        editor.create();
        $("#_contents").find(".w-e-text-container").css("height", "200px");
        var ctx = uploadify({
            container: '#img' + index
        });
        var step = {
            index: index,
            type: 'image',
            text: editor,
            image: ctx
        };
        es.push(step);

        if (content) {
            if (content.text) {
                editor.txt.html(content.text);
            }
            if (content.image) {
                var images = [];
                images.push(content.image);
                ctx.setContent(images);
            }
            if (content.file) {
                var filess = [];
                filess.push(content.file);
                ctx.setContent(filess);
            }
        }
    };

    var addInput = function (content) {
        var index = Math.round(Math.random() * 10000);
        var container = $("<div>").attr("id", "step" + index);
        var div = $("<div>").attr("id", "editor" + index)
        var input = $("<input>").attr("id", "input" + index).css({
            "width": "300px",
            "margin-top": "8px"
        });
        var del = $("<button>").attr("type", "button").attr("id", "del" + index).text("删除").css({
            "float": "right",
            "margin": "10px 15px"
        }).click(function () {
            if (confirm("是否删除该步骤？")) {
                $("#step" + index).remove();
                for (var i = 0; i < es.length; i++) {
                    if (es[i].index == index) {
                        es.splice(i, 1);
                    }
                }
            }
        });
        var clearfix = $("<div>").css({
            "clear": "both"
        });
        container.append(div).append(input).append(del).append(clearfix);
        $("#_contents").append(container);
        var E = window.wangEditor;
        var editor = new E('#editor' + index);
        editor.customConfig.uploadImgShowBase64 = true;
        editor.create();
        $("#_contents").find(".w-e-text-container").css("height", "160px");
        var step = {
            index: index,
            type: 'input',
            text: editor,
            input: input
        };
        es.push(step);

        if (content) {
            if (content.text) {
                editor.txt.html(content.text);
            }
            if (content.input) {
                input.val(content.input);
            }
        }
    };
    var clock = false;
    var addExcel = function (content) {
        var index = Math.round(Math.random() * 10000);
        var container = $("<div>").attr("id", "step" + index);
        var div = $("<div>").attr("id", index)
        var input = $("<input>").attr("type", "file").attr("id", "file");
        var del = $("<button>").attr("type", "button").attr("id", "del" + index).text("删除").css({
            "float": "right",
            "margin": "10px 15px"
        }).click(function () {
            if (confirm("是否删除该步骤？")) {
                $("#step" + index).remove();
                clock = false;
                for (var i = 0; i < es.length; i++) {
                    if (es[i].index == index) {
                        es.splice(i, 1);
                    }
                }
            }
        });
        var clearfix = $("<div>").css({
            "clear": "both"
        });
        container.append(div).append(input).append(del).append(clearfix);
        $("#_contents").append(container);
        var E = window.wangEditor;
        var editor = new E('#editor' + index);
        editor.customConfig.uploadImgShowBase64 = true;
        editor.create();
        $("#_contents").find(".w-e-text-container").css("height", "80px");
        var step = {
            index: index,
            type: 'comment',
            text: editor,
            input: input
        };
        es.push(step);

        if (content) {
            if (content.text) {
                editor.txt.html(content.text);
            }
            if (content.input) {
                input.val(content.input);
            }
        }
    };
    var addImageNoUp = function (content) {
        var index = Math.round(Math.random() * 10000);
        var container = $("<div>").attr("id", "step" + index);
        var div = $("<div>").attr("id", "editor" + index)
        var imgs = $("<div>").attr("id", "img" + index);
        var del = $("<button>").attr("type", "button").attr("id", "del" + index).text("删除").css({
            "float": "right",
            "margin": "10px 15px"
        }).click(function () {
            if (confirm("是否删除该步骤？")) {
                $("#step" + index).remove();
                for (var i = 0; i < es.length; i++) {
                    if (es[i].index == index) {
                        es.splice(i, 1);
                    }
                }
            }
        });
        var clearfix = $("<div>").css({
            "clear": "both"
        });
        container.append(div).append(imgs).append(del).append(clearfix);
        $("#_contents").append(container);
        var E = window.wangEditor;
        var editor = new E('#editor' + index);
        editor.customConfig.uploadImgShowBase64 = true;
        editor.create();
        $("#_contents").find(".w-e-text-container").css("height", "200px");
        var ctx = uploadify({
            container: '#img' + index
        });
        var step = {
            index: index,
            type: 'imagenoup',
            text: editor,
            image: ctx
        };
        es.push(step);

        if (content) {
            if (content.text) {
                editor.txt.html(content.text);
            }
            if (content.imagelist) {
                var images = [];
                for (var o = 0; o < content.imagelist.length; o++) {
                    images.push(content.imagelist[o])
                }

                ctx.setContent(images);
            }
            if (content.file) {
                var filess = [];
                filess.push(content.file);
                ctx.setContent(filess);
            }
        }
    };
    <#if task??>
    var steps = eval(${task.contents});
    if (steps.length > 0) {
        for (var i in steps) {
            if (steps[i].type == 'input') {
                addInput(steps[i]);
            }
            if (steps[i].type == 'image') {
                addImage(steps[i]);
            }
            if (steps[i].type == 'comment') {
                clock = true;
                addExcel();
            }
            if (steps[i].type == 'imagenoup') {

                addImageNoUp(steps[i]);
            }
        }
    }
    </#if>


    var change = function () {
        if ($("#needCheck").val() == "True") {
            return;
        }
        var s = content;
        if ($("#keywords").val()) {
            s = s.replace(/keywords/g, $("#keywords").val());
        }
        if ($("#title").val()) {
            s = s.replace(/title/g, $("#title").val());
        }
        if ($("#appStore").val()) {
            s = s.replace(/appStore/g, $("#appStore option:selected").text());
        }
        if ($("#rank").val()) {
            s = s.replace(/rank/g, $("#rank").val());
        }
        if ($("#minutes").val()) {
            s = s.replace(/minutes/g, $("#minutes").val());
        }
        editor.txt.html(s);
    };

    $(function () {
        $("#add_btn").click(function () {
            addImage();
        });
        $("#add_btn2").click(function () {
            addInput();
        });
        var ctx = uploadify({
            container: '#imgs'
        });
        $("#add_btn4").click(function () {
            clock = true;
            addImageNoUp();
        });


        $("#save_btn").click(function () {
            var items = [];

            for (var i = 0; i < es.length; i++) {
                if (es[i].type == 'input') {
                    var item = {
                        type: es[i].type,
                        text: es[i].text.txt.html(),
                        input: es[i].input.val()
                    };
                    items.push(item);
                }
                if (es[i].type == 'image') {
                    var item = {
                        type: es[i].type,
                        text: es[i].text.txt.html(),
                        image: es[i].image.images()[0]
                    };
                    console.log(es[i].image.images()[0]);
                    items.push(item);
                }
                if (es[i].type == 'comment') {
                    var item = {
                        type: es[i].type,
                        text: ''
                    };
                    items.push(item);
                }
                if (es[i].type == 'imagenoup') {
                    var imglist = new Array();
                    for (var o = 0; o < es[i].image.images().length; o++) {
                        imglist.push(es[i].image.images()[o])
                    }

                    var item = {
                        type: es[i].type,
                        text: es[i].text.txt.html(),
                        imagelist: imglist
                    };
                    console.log(es[i].image.images()[0]);
                    items.push(item);
                }
            }


            if (!$("#title").val()) {
                alert("请填入应用名称！");
                return false;
            }
            if (!$("#icon").val()) {
                alert("请填入应用图标！");
                return false;
            }
            if (!$("#packagename").val()) {
                alert("请填入应用包名！");
                return false;
            }
            if (!$("#size").val()) {
                alert("请填入应用包大小！");
                return false;
            }
            if (!$("#appStore").val()) {
                alert("请选择应用市场！");
                return false;
            }
            if (!$("#keywords").val()) {
                alert("请填入应用关键词！");
                return false;
            }
            if (!$("#rank").val()) {
                alert("请填入应用市场排名！");
                return false;
            }
            if (!$("#minutes").val()) {
                alert("请填入试玩时间！");
                return false;
            }
            if (!$("#total").val()) {
                alert("请填入任务总量！");
                return false;
            }
            if (!$("#amount").val()) {
                alert("请填入每日限量！");
                return false;
            }
            if (!$("#increase").val()) {
                $("#increase").val(0)
            }
            if (!$("#label").val()) {
                alert("请填入展示奖励！");
                return false;
            }
            if ($("#reward").val() == 'Random') {
                if (!/:|：/.test($("#worth").val())) {
                    alert("格式为n：m或者n:m，请填入正确的格式！");
                    return false;
                }
            } else {
                if (!/^[1-9]\d*$/.test($("#worth").val())) {
                    alert("请填入计算奖励需正整数！");
                    return false;
                }
            }
            $("#contents").val(JSON.stringify(items));
            //alert($("#contents").val());
            $("#images").val(JSON.stringify(ctx.images()));
            $.ajax({
                type: "post",
                url: "/soso/save",
                data: $("#form").serialize(),
                success: function (res) {
                    alert(res);
                }
            });
        });

    });
</script>
</body>
</html>
